﻿using Microsoft.AspNetCore.Mvc.Razor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace MvcSample.ViewLocationExpanders
{
    public class ThemeViewLocationExpander
        : IViewLocationExpander
    {
        public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
        {
             if (context.Values.TryGetValue("theme",out string val))
            {
                var key = "Themes";
                return new List<string>() { $"/{key}/{val}/Shared/{{0}}.cshtml", $"/{key}/{val}/{{1}}/{{0}}.cshtml" }.Concat(viewLocations);
            }
            return viewLocations;             
        }

        public void PopulateValues(ViewLocationExpanderContext context)
        {
            context.Values.TryAdd("theme","Blue"); 
        }
    }
}
